package com.qfoud.edu.dbutils.framwork.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author xiaobobo
 * @title: JdbcUtils
 * @projectName cd-java-2303-project-parent
 * @description: 工具类
 * @date 2023/5/11  10:30
 */
public class JdbcUtils {

    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.out.println("加载我们的驱动出错");
        }
    }

    /**
     * 获取连接
     * @return
     */
    public static Connection getConnection(String url,String username,String password){
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url, username, password);
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("获取数据库连接失败");
        }
        return connection;
    }





}
